package com.itNiuNiu.config;

import com.itNiuNiu.interceptor.ResourceInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.servlet.config.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: lenovo
 * @time: 2024-03-06 13:10
 */
@Configuration
@ComponentScan("com.itNiuNiu.controller")
@PropertySource("classpath:ignoreUrl.properties")
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {
    /* 后续的管理员需要忽视文件 */
    @Value("#{'${ignoreUrl}'.split(',')}")
    private List<String> ignoreUrl;

    public ResourceInterceptor resourceInterceptor(){
        return new ResourceInterceptor(ignoreUrl);
    }
    //开启静态资源的访问
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/admin/",".jsp");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(resourceInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**","/js/**","/img/**");
    }
}
